package com.xiaoshuidi.cloud.module.rooms.mq.consumer;

import com.alibaba.fastjson.JSONObject;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.roomel.vo.RoomelCreateReqVO;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.roomel.vo.RoomelUpdateReqVO;
import com.xiaoshuidi.cloud.module.rooms.service.IRoomelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.function.Consumer;

/**
 * @author hans.zhang
 */
//@Component
@Slf4j
public class RoomEsConsumer {

    @Autowired
    private IRoomelService iRoomelService;

    //消费-房源-单个更新
    @Bean
    public Consumer<String> RoomEsConsumerUpdate() {
        return message -> {

            log.info("消费者-RoomEsConsumerA : message = " + message);

            RoomelUpdateReqVO reqVO = JSONObject.parseObject(message, RoomelUpdateReqVO.class);
            Boolean result = iRoomelService.updateCover(reqVO);
            log.info("消费-房源-单个更新，消费是否成功："+result);
        };
    }

    //消费-房源-批量更新
    @Bean
    public Consumer<List<JSONObject>> RoomEsConsumerUpdateBatch() {
        return message -> {

            List<RoomelUpdateReqVO> list = JSONObject.parseArray(JSONObject.toJSONString(message), RoomelUpdateReqVO.class);

            Boolean result = iRoomelService.updateCoverBatch(list);
            log.info("消费-房源-批量更新，消费是否成功："+result);
        };
    }

    //消费-房源-批量新增
    @Bean
    public Consumer<List<JSONObject>> RoomEsAConsumerListAdd() {
        return message -> {
            log.info("消费-房源-批量新增");
            List<RoomelCreateReqVO> list = JSONObject.parseArray(JSONObject.toJSONString(message), RoomelCreateReqVO.class);
            Boolean result = iRoomelService.listadd(list);
            log.info("消费-房源-批量新增,消费是否成功："+result);
        };
    }

    //消费-房源-删除
    @Bean
    public Consumer<String> RoomEsAConsumerDeleteById() {
        return message -> {

            Boolean result = iRoomelService.deleteByesid(message.toString());
            log.info("消费-房源-删除，消费是否成功："+result);
        };
    }

}
